Total Complexity | 2 |
Total Lines | 22 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | import {QueryHandler} from '@nestjs/cqrs'; |
||
8 | |||
9 | @QueryHandler(GetProjectByIdQuery) |
||
10 | export class GetProjectByIdQueryHandler { |
||
11 | constructor( |
||
12 | @Inject('IProjectRepository') |
||
13 | private readonly projectRepository: IProjectRepository |
||
14 | ) {} |
||
15 | |||
16 | public async execute(query: GetProjectByIdQuery): Promise<ProjectView> { |
||
17 | const project = await this.projectRepository.findOneById(query.id); |
||
18 | if (!project) { |
||
19 | throw new ProjectNotFoundException(); |
||
20 | } |
||
21 | |||
22 | const customer = project.getCustomer(); |
||
23 | |||
24 | return new ProjectView( |
||
25 | project.getId(), |
||
26 | project.getName(), |
||
27 | project.getDayDuration(), |
||
28 | project.getInvoiceUnit(), |
||
29 | new CustomerView(customer.getId(), customer.getName()) |
||
30 | ); |
||
33 |